package chpt02;

public class MethodDemo04 {

	public static void main(String[] args) {
		int a[] = {9,5,1,2,6,3,4,8,7,5}, i;
		fun(a,10);
		for (i=0; i<10; i++)
			System.out.print(a[i] + " ");
		System.out.println();
	}
	// 定义fun()方法，实现最大值和最小值位置对换
	public static void fun(int a[], int n){
		int i, temp;
		int max = 0, min = 0;
		for (i=1; i<n; i++){
			if (a[max] < a[i])
				max = i;
			if (a[min] > a[i])
				min = i;
		}
		temp = a[max];
		a[max] = a[min];
		a[min] = temp;
	}
}
